package com.zz.info.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.zz.info.dao.LikeDao;
import com.zz.info.domain.LikeDO;
import com.zz.info.service.LikeService;



@Service
public class LikeServiceImpl implements LikeService {
	@Autowired
	private LikeDao likeDao;
	

	@Override
	public List<LikeDO> list(Map<String, Object> map){
		return likeDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return likeDao.count(map);
	}
	
	@Override
	public int toggleLike(String likeType,Long infoId,String userId){
		int i=remove( likeType, infoId, userId);
		if(i>0){
			return i;
		}
		LikeDO t=new LikeDO();
		t.setInfoId(infoId);
		t.setUserId(userId);
		t.setInfoType(likeType);
		return likeDao.save(t);
	}

	@Override
	public int remove(String likeType,Long infoId,String userId){
		Map t=new HashMap();
		t.put("infoId",infoId);
		t.put("infoType",likeType);
		t.put("userId",userId);
		return likeDao.remove(t);
	}
	


	
}
